package com.yuanfeng.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.base.entity.BaseDistributorGradeEntity;
import com.yuanfeng.base.mapper.BaseDistributorGradeMapper;
import com.yuanfeng.base.service.BaseDistributorGradeService;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class BaseDistributorGradeServiceImpl extends ServiceImpl<BaseDistributorGradeMapper, BaseDistributorGradeEntity>
    implements BaseDistributorGradeService{

    @Override
    public ResponseResult updateGrade(Map<String, Object> map) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(map.get("token").toString());

        if (null == userInfo) {
            return ResponseResult.fail(BizCodeEnume.USER_DOES_NOT_EXIST);
        }
        map.put("updateBy",StringUtils.isEmpty(userInfo.getUserRealname())?"未知":userInfo.getUserRealname());
        this.baseMapper.updateGrade(map);
        return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
    }

    @Override
    public ResponseResult queryGrade(Map<String, Object> map) {
        List<BaseDistributorGradeEntity> list=this.baseMapper.selectList(new LambdaQueryWrapper<BaseDistributorGradeEntity>());
        return ResponseResult.success(list);
    }
}




